package com.itheima.controller;

import com.itheima.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@Controller
@RequestMapping(path = "/params")
public class ParamsController {

    @RequestMapping("/demo1")
    public String demo1(Integer page,Integer pageSize){
        System.out.println(page+" "+pageSize);
        return "success";
    }

    @RequestMapping(value = "/demo2",method = RequestMethod.POST)
    public String demo2(User user){
        System.out.println(user);
        return "success";
    }

    @RequestMapping("/demo3")
    public String demo3(User user){
        System.out.println(user);
        return "success";
    }

    @RequestMapping("/demo4")
    public String demo4(User user){
        System.out.println(user);
        return "success";
    }

    @RequestMapping("/demo5")
    public String demo5(User user){
        System.out.println(user);
        return "success";
    }

    @RequestMapping("/demo6")
    public String demo6(String[] hobby){
        System.out.println(Arrays.toString(hobby));
        return "success";
    }

    @RequestMapping("/demo7")
    public String demo7(@RequestParam("hobby") List<String> hobby){
        System.out.println(hobby);
        return "success";
    }

    @RequestMapping(path = "/demo8")
    public String demo8(Model model){
        //向Model中存入数据
        model.addAttribute("username","杨过");
        return "success";
    }

}
